/*
 * Created on Feb 15, 2007
 */
package sandboxmv.panels;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.geom.Ellipse2D;

import javax.swing.JPanel;

import ecologylab.game2d.terrain.Wall;

import sandboxmv.gamedata.ControlledHero;
import sandboxmv.gamedata.GameData;
import sandboxmv.map.Room;

/**
 * @author Zach Toups (toupsz@gmail.com)
 */
public class GameDisplayPanel extends JPanel
{
    private static final long serialVersionUID = 1L;

    private ControlledHero hero;
    
    private GameData gameData;
    
    public GameDisplayPanel(int xSize, int ySize, ControlledHero hero, GameData gameData)
    {
        Dimension d = new Dimension(xSize, ySize);
        this.setSize(d);
        this.setPreferredSize(d);
        this.setMinimumSize(d);
        this.setMaximumSize(d);
        this.hero = hero;
        this.gameData = gameData;
    }
    
    /**
     * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
     */
    @Override protected void paintComponent(Graphics g)
    {
        Graphics2D g2 = (Graphics2D) g;

        // save the color and transform
        Color saveColor = g2.getColor();
        AffineTransform saveXForm = g2.getTransform();

        Room currentRoom = hero.getCurrentRoom();
        
        // scale the view to fit the whole map in the window
        g2.scale(((double) this.getWidth())
                / ((double) currentRoom.getWidth()), ((double) this
                .getHeight())
                / ((double) currentRoom.getHeight()));

        g2.setColor(Color.BLACK);
        g2.fillRect(0, 0, currentRoom.getWidth(), currentRoom.getHeight());
        
        g2.setColor(Color.BLUE);
        // paint the map
        for (Wall wall : currentRoom.getSurfaces())
        {
            g2.draw(wall);
        }

        double xPos = hero.getHero().getPos().getX();
        double yPos = hero.getHero().getPos().getY();
        g2.setColor(Color.WHITE);
        g2.translate(xPos, yPos);
        g2.fill(new Ellipse2D.Double(-5, -5, 10, 10));
        
        g2.setTransform(saveXForm);
        g2.setColor(saveColor);
    }


}
